<?php

namespace App\Repository\XhApi;

use App\Models\Xh\PaysModel;
use App\Repository\BaseRepository;

class PaysRepository extends BaseRepository
{
    public $model;
    public $log;

    public function __construct()
    {
        $this->model = new PaysModel();
        parent::__construct();
    }

    public function index($params, $page = 1, $limit = 10)
    {
        $where = [];
        if (!empty($params['ordersno'])) {
            $where['where']['ordersno'] = $params['ordersno'];
        }
        if (!empty($params['out_trade_no'])) {
            $where['where']['out_trade_no'] = $params['out_trade_no'];
        }
        if (isset($params['status']) && $params['status'] != '') {
            $where['where']['status'] = (int)$params['status'];
        }
        if (!empty($params['dateRange'])) {
            $time = $params['dateRange'];
            $where['between']['created_at'] = $time;
        }
        return $this->unifiedGetPage($where, $page, $limit);
    }

//    快速修改状态
    public function changeStatus($ordersno, $status = 0)
    {
        return $this->unifiedUpdateStatus($ordersno, $status);
    }

//新增内容
    public function add($postData)
    {
        return $this->unifiedAdd($postData, [
            'out_trade_no' => '缺少外部单号',
            'transaction_id' => '支付单号必须有'
        ], 'transaction_id');
    }

//修改内容
    public function edit($postData)
    {
        return $this->unifiedEdit($postData, [
            'id' => '请指明修改的数据编号',
            'out_trade_no' => '缺少外部单号',
            'transaction_id' => '支付单号必须有'
        ], null);
    }
}
